1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.DropTargetAsync; 26 27 private import gdk.ContentFormats; 28 private import gdk.Drop; 29 private import glib.ConstructionException; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.EventController; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * `GtkDropTargetAsync` is an event controller to receive Drag-and-Drop 40 * operations, asynchronously. 41 * 42 * It is the more complete but also more complex method of handling drop 43 * operations compared to [class@Gtk.DropTarget], and you should only use 44 * it if `GtkDropTarget` doesn't provide all the features you need. 45 * 46 * To use a `GtkDropTargetAsync` to receive drops on a widget, you create 47 * a `GtkDropTargetAsync` object, configure which data formats and actions 48 * you support, connect to its signals, and then attach it to the widget 49 * with [method@Gtk.Widget.add_controller]. 50 * 51 * During a drag operation, the first signal that a `GtkDropTargetAsync` 52 * emits is [signal@Gtk.DropTargetAsync::accept], which is meant to determine 53 * whether the target is a possible drop site for the ongoing drop. The 54 * default handler for the ::accept signal accepts the drop if it finds 55 * a compatible data format and an action that is supported on both sides. 56 * 57 * If it is, and the widget becomes a target, you will receive a 58 * [signal@Gtk.DropTargetAsync::drag-enter] signal, followed by 59 * [signal@Gtk.DropTargetAsync::drag-motion] signals as the pointer moves, 60 * optionally a [signal@Gtk.DropTargetAsync::drop] signal when a drop happens, 61 * and finally a [signal@Gtk.DropTargetAsync::drag-leave] signal when the 62 * pointer moves off the widget. 63 * 64 * The ::drag-enter and ::drag-motion handler return a `GdkDragAction` 65 * to update the status of the ongoing operation. The ::drop handler 66 * should decide if it ultimately accepts the drop and if it does, it 67 * should initiate the data transfer and finish the operation by calling 68 * [method@Gdk.Drop.finish]. 69 * 70 * Between the ::drag-enter and ::drag-leave signals the widget is a 71 * current drop target, and will receive the %GTK_STATE_FLAG_DROP_ACTIVE 72 * state, which can be used by themes to style the widget as a drop target. 73 */ 74 public class DropTargetAsync : EventController 75 { 76 /** the main Gtk struct */ 77 protected GtkDropTargetAsync* gtkDropTargetAsync; 78 79 /** Get the main Gtk struct */ 80 public GtkDropTargetAsync* getDropTargetAsyncStruct(bool transferOwnership = false) 81 { 82 if (transferOwnership) 83 ownedRef = false; 84 return gtkDropTargetAsync; 85 } 86 87 /** the main Gtk struct as a void* */ 88 protected override void* getStruct() 89 { 90 return cast(void*)gtkDropTargetAsync; 91 } 92 93 /** 94 * Sets our main struct and passes it to the parent class. 95 */ 96 public this (GtkDropTargetAsync* gtkDropTargetAsync, bool ownedRef = false) 97 { 98 this.gtkDropTargetAsync = gtkDropTargetAsync; 99 super(cast(GtkEventController*)gtkDropTargetAsync, ownedRef); 100 } 101 102 103 /** */ 104 public static GType getType() 105 { 106 return gtk_drop_target_async_get_type(); 107 } 108 109 /** 110 * Creates a new `GtkDropTargetAsync` object. 111 * 112 * Params: 113 * formats = the supported data formats 114 * actions = the supported actions 115 * 116 * Returns: the new `GtkDropTargetAsync` 117 * 118 * Throws: ConstructionException GTK+ fails to create the object. 119 */ 120 public this(ContentFormats formats, GdkDragAction actions) 121 { 122 auto __p = gtk_drop_target_async_new((formats is null) ? null : formats.getContentFormatsStruct(true), actions); 123 124 if(__p is null) 125 { 126 throw new ConstructionException("null returned by new"); 127 } 128 129 this(cast(GtkDropTargetAsync*) __p, true); 130 } 131 132 /** 133 * Gets the actions that this drop target supports. 134 * 135 * Returns: the actions that this drop target supports 136 */ 137 public GdkDragAction getActions() 138 { 139 return gtk_drop_target_async_get_actions(gtkDropTargetAsync); 140 } 141 142 /** 143 * Gets the data formats that this drop target accepts. 144 * 145 * If the result is %NULL, all formats are expected to be supported. 146 * 147 * Returns: the supported data formats 148 */ 149 public ContentFormats getFormats() 150 { 151 auto __p = gtk_drop_target_async_get_formats(gtkDropTargetAsync); 152 153 if(__p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true); 159 } 160 161 /** 162 * Sets the @drop as not accepted on this drag site. 163 * 164 * This function should be used when delaying the decision 165 * on whether to accept a drag or not until after reading 166 * the data. 167 * 168 * Params: 169 * drop = the `GdkDrop` of an ongoing drag operation 170 */ 171 public void rejectDrop(Drop drop) 172 { 173 gtk_drop_target_async_reject_drop(gtkDropTargetAsync, (drop is null) ? null : drop.getDropStruct()); 174 } 175 176 /** 177 * Sets the actions that this drop target supports. 178 * 179 * Params: 180 * actions = the supported actions 181 */ 182 public void setActions(GdkDragAction actions) 183 { 184 gtk_drop_target_async_set_actions(gtkDropTargetAsync, actions); 185 } 186 187 /** 188 * Sets the data formats that this drop target will accept. 189 * 190 * Params: 191 * formats = the supported data formats or %NULL for any format 192 */ 193 public void setFormats(ContentFormats formats) 194 { 195 gtk_drop_target_async_set_formats(gtkDropTargetAsync, (formats is null) ? null : formats.getContentFormatsStruct()); 196 } 197 198 /** 199 * Emitted on the drop site when a drop operation is about to begin. 200 * 201 * If the drop is not accepted, %FALSE will be returned and the drop target 202 * will ignore the drop. If %TRUE is returned, the drop is accepted for now 203 * but may be rejected later via a call to [method@Gtk.DropTargetAsync.reject_drop] 204 * or ultimately by returning %FALSE from a [signal@Gtk.DropTargetAsync::drop] 205 * handler. 206 * 207 * The default handler for this signal decides whether to accept the drop 208 * based on the formats provided by the @drop. 209 * 210 * If the decision whether the drop will be accepted or rejected needs 211 * further processing, such as inspecting the data, this function should 212 * return %TRUE and proceed as is @drop was accepted and if it decides to 213 * reject the drop later, it should call [method@Gtk.DropTargetAsync.reject_drop]. 214 * 215 * Params: 216 * drop = the `GdkDrop` 217 * 218 * Returns: %TRUE if @drop is accepted 219 */ 220 gulong addOnAccept(bool delegate(Drop, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 221 { 222 return Signals.connect(this, "accept", dlg, connectFlags ^ ConnectFlags.SWAPPED); 223 } 224 225 /** 226 * Emitted on the drop site when the pointer enters the widget. 227 * 228 * It can be used to set up custom highlighting. 229 * 230 * Params: 231 * drop = the `GdkDrop` 232 * x = the x coordinate of the current pointer position 233 * y = the y coordinate of the current pointer position 234 * 235 * Returns: Preferred action for this drag operation. 236 */ 237 gulong addOnDragEnter(GdkDragAction delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 238 { 239 return Signals.connect(this, "drag-enter", dlg, connectFlags ^ ConnectFlags.SWAPPED); 240 } 241 242 /** 243 * Emitted on the drop site when the pointer leaves the widget. 244 * 245 * Its main purpose it to undo things done in 246 * `GtkDropTargetAsync`::drag-enter. 247 * 248 * Params: 249 * drop = the `GdkDrop` 250 */ 251 gulong addOnDragLeave(void delegate(Drop, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 252 { 253 return Signals.connect(this, "drag-leave", dlg, connectFlags ^ ConnectFlags.SWAPPED); 254 } 255 256 /** 257 * Emitted while the pointer is moving over the drop target. 258 * 259 * Params: 260 * drop = the `GdkDrop` 261 * x = the x coordinate of the current pointer position 262 * y = the y coordinate of the current pointer position 263 * 264 * Returns: Preferred action for this drag operation. 265 */ 266 gulong addOnDragMotion(GdkDragAction delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 267 { 268 return Signals.connect(this, "drag-motion", dlg, connectFlags ^ ConnectFlags.SWAPPED); 269 } 270 271 /** 272 * Emitted on the drop site when the user drops the data onto the widget. 273 * 274 * The signal handler must determine whether the pointer position is in a 275 * drop zone or not. If it is not in a drop zone, it returns %FALSE and no 276 * further processing is necessary. 277 * 278 * Otherwise, the handler returns %TRUE. In this case, this handler will 279 * accept the drop. The handler must ensure that [method@Gdk.Drop.finish] 280 * is called to let the source know that the drop is done. The call to 281 * [method@Gdk.Drop.finish] must only be done when all data has been received. 282 * 283 * To receive the data, use one of the read functions provided by 284 * [class@Gdk.Drop] such as [method@Gdk.Drop.read_async] or 285 * [method@Gdk.Drop.read_value_async]. 286 * 287 * Params: 288 * drop = the `GdkDrop` 289 * x = the x coordinate of the current pointer position 290 * y = the y coordinate of the current pointer position 291 * 292 * Returns: whether the drop is accepted at the given pointer position 293 */ 294 gulong addOnDrop(bool delegate(Drop, double, double, DropTargetAsync) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 295 { 296 return Signals.connect(this, "drop", dlg, connectFlags ^ ConnectFlags.SWAPPED); 297 } 298 }